package com.mvu.banana.domain.server;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * Class description...
 *
 * @author mvu
 */
public class ServerProperties extends Properties {
  private static ServerProperties instance;
  private static final String PERSISTENCE_UNIT = "persistence-unit";

  private ServerProperties() {
  }

  public static ServerProperties get() throws RuntimeException {
    if (instance == null) {
      instance = new ServerProperties();
      InputStream propertiesFile = ServerProperties.class.getResourceAsStream("/server.properties");
      try {
        instance.load(propertiesFile);
      } catch (IOException e) {
        e.printStackTrace();
        throw new RuntimeException(e);
      }
    }
    return instance;
  }

  public static String getPersistenceUnit() {
    return get().getProperty(PERSISTENCE_UNIT);
  }

  public static String get(String key) {
    return get().getProperty(key);
  }
}
